package com.kfirszt.elearning.elearningImport;

import javax.xml.bind.JAXBException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.kfirszt.elearning.dictionary.Province;
import com.kfirszt.elearning.elearningImport.TerytImport.Row;
import com.kfirszt.elearning.persistence.model.City;
import com.kfirszt.elearning.persistence.service.CityService;

@Component
public class TerytImportProcessor {

	@Autowired
	private CityService cityService;
	
	public void process() throws JAXBException {
		Province[] provinces = Province.values();
		TerytImport baza = TerytImport.process();
		for(Row row : baza.getCatalog().getRow()){
			City city = new City();
			city.setName(row.getCol().get(6).getValue());
			city.setProvince(provinces[Integer.parseInt(row.getCol().get(0).getValue())/2-1]);
			cityService.create(city);
		}
	}
	
	public static void main(String[] args) throws JAXBException {
		new TerytImportProcessor().process();
	}
}
